package com.asktgapp.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.asktgapp.application.MyApplication;
import com.asktgapp.utils.NetworkUtils;


/**
 * Created by Administrator on 2017/10/31.
 */

public class JGOnePixelReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {    //屏幕关闭启动1像素Activity
            if (NetworkUtils.isBackground()) {
                MyApplication.onePixelStart = true;
                Log.e("onePixelActivity", "后台状态，黑屏");
//                Intent it = new Intent(MyApplication.getInstance(), JGOnePixelActivity.class);
//                it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                MyApplication.getInstance().startActivity(it);
            } else {
                MyApplication.onePixelStart = false;
                Log.e("onePixelActivity", "前台状态，黑屏");
            }
            Intent sound = new Intent(context, SoundService.class);
            context.startService(sound);
        } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {   //屏幕打开 结束1像素
            if (MyApplication.onePixelStart) {
                Log.e("onePixelActivity", "亮屏");
//                context.sendBroadcast(new Intent("finishOneP"));
//                Intent main = new Intent(Intent.ACTION_MAIN);
//                main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//                main.addCategory(Intent.CATEGORY_HOME);
//                context.startActivity(main);
            }
        }
//        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {    //屏幕关闭启动1像素Activity
//            Intent it = new Intent(context, JGOnePixelActivity.class);
//            it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            context.startActivity(it);
//        } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {   //屏幕打开 结束1像素
//            context.sendBroadcast(new Intent("finishOneP"));
//            Intent main = new Intent(Intent.ACTION_MAIN);
//            main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//            main.addCategory(Intent.CATEGORY_HOME);
//            context.startActivity(main);
//        }
    }
}
